package zhang.lao.console.timer;/**
 * Created by zhangqin on 2017/9/28.
 */

import com.arronlong.httpclientutil.exception.HttpProcessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import zhang.lao.build.tool.date.DateStyle;
import zhang.lao.build.tool.date.DateUtil;
import zhang.lao.console.service.AutoMachineSplitService;
import zhang.lao.service.console.WorkMapSplitService;
import zhang.lao.service.search.SearchService;
import zhang.lao.service.weather.WeatherService;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;

/**
 * @author
 * @create 2017-09-28 14:25
 **/
public class AutoSplitMap {
        private static final Logger logger = LoggerFactory.getLogger(AutoSplitMap.class);
    @Resource
    private WorkMapSplitService workMapSplitService;
    @Resource
    private AutoMachineSplitService autoMachineSplitService;

    @Resource
    private WeatherService weatherService;
    public synchronized void splitMap(){

        logger.info("分割农田");
        Calendar calc =Calendar.getInstance();
        calc.setTime(new Date());
        calc.add(calc.DATE, -1);
        Date minDate = calc.getTime();
        workMapSplitService.initWork(DateUtil.DateToString(minDate, DateStyle.YYYY_MM_DD));
        logger.info("分割农田结束");
    }

    public synchronized void autoMachineArea(){
        Calendar calc =Calendar.getInstance();
        calc.setTime(new Date());
        calc.add(calc.DATE, -1);
        Date minDate = calc.getTime();
        autoMachineSplitService.split(DateUtil.DateToString(minDate, DateStyle.YYYY_MM_DD));
    }


    public void weatherSee(){
     //    weatherService.logWeather();
    }

    @Resource
    private SearchService searchService;

    public synchronized void synLatLng(){
        try {
            searchService.synLatLngToSearch();
        } catch (HttpProcessException e) {
            logger.error(e.getLocalizedMessage(),e);
        }
    }

}
